package com.test.ftp;

import java.net.Inet6Address;
import java.net.InetAddress;
import java.net.NetworkInterface;
import java.net.SocketException;
import java.util.Enumeration;

public class FtpIp {

	public static InetAddress getLocalIP2() {
		InetAddress ip = null;
		try {
			Enumeration<?> e1 = (Enumeration<?>) NetworkInterface
					.getNetworkInterfaces();
			while (e1.hasMoreElements()) {
				NetworkInterface ni = (NetworkInterface) e1.nextElement();
				System.out.println(ni.getName() + ni.getInetAddresses());
				// if (!ni.getName().equals("eth0")) {
				// System.out.println(ni.getName()+ni.getInetAddresses());
				// continue;
				// } else {
				Enumeration<?> e2 = ni.getInetAddresses();
				while (e2.hasMoreElements()) {
					InetAddress ia = (InetAddress) e2.nextElement();
					ip = ia;
					System.out.println("\t" + ia);
					if (ia instanceof Inet6Address)
						continue;
					// ip = ia.getHostAddress();
				}
				break;
				// }
			}
		} catch (SocketException e) {
			e.printStackTrace();
			System.exit(-1);
		}
		return ip;
	}
}
